package com.jade.store.wechat.biz.service.auth;

import com.jade.framework.base.context.ApplicationContextUtils;
import com.jade.framework.cache.CacheService;
import com.jade.store.wechat.biz.common.WxConstantUtil;
import com.jade.store.wechat.biz.protocol.three.Oauth2ComponentReq;
import com.jade.store.wechat.biz.service.BaseWxService;

/**
 * Created with IntelliJ IDEA.
 * User: jinya
 * Date: 2016/12/13
 * Time: 18:09
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
public class Oauth2ComponentService extends BaseWxService {
    private CacheService cacheService = ApplicationContextUtils.getBean("system_cacheService");
    public Oauth2ComponentService(String appid) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        super(appid,WxConstantUtil.api_oauth2_component);
    }

    /**
     * 请求支付服务
     * @param req 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    public String request(Oauth2ComponentReq req) throws Exception {
        //--------------------------------------------------------------------
        //发送HTTPS的Post请求到API地址
        //--------------------------------------------------------------------
        super.setApiURL(super.getApiURL()+"&appid="+req.getAppid()+"&code="+req.getCode()+"&grant_type="+req.getGrant_type()+"&component_appid="+req.getComponent_appid());
        String responseString = sendJsonPost(req);
        return responseString;
    }
}
